import pytest,time
from re import search
from data import db
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import Keys
sql = db('root','yidong666','10.59.9.12','a3mall')

@pytest.fixture(scope="class")
def driver():
    driver=webdriver.Firefox()
    driver.get('http://10.59.9.12:7001/')
    driver.maximize_window()
    #将driver传递给测试用例
    yield driver
    #后置操作用来关闭相当于teardown
    time.sleep(3)
    driver.quit()

def test_a3mall_login(driver):
    # 执行搜索的语句（放哪都行）数据库断言1
    ye = sql.select('select amount from mall_users where username = "13811033962"')
    print(ye[0][0])
    #点击登录
    driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
    time.sleep(3)
    #输入框输入账号
    driver.find_element(By.NAME,'username').send_keys('13811033962')
    #输入框输入密码
    driver.find_element(By.NAME,'password').send_keys('123456')
    time.sleep(15)
    #点击登录按钮
    driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
    time.sleep(6)
    #断言,登陆成功：欢迎回来
    dy1=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text
    print("登录成功断言：",dy1)
    #数据库断言余额
    dy2 = driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
    print(dy2.replace('¥ ', ''))
    print("账户余额断言：", dy2)